//
//  Mo-atrribute-base.swift
//  soapp
//
//  Created by zhu xietong on 2017/10/11.
//

import Foundation
import AsyncDisplayKit


extension ASDisplayNode{
    private struct __AssociatedKeys {
        static var notify_key = "__easy_notify_key"
        
    }
    
    public var __notice: EasyNotification {
        get {
            if let obj = objc_getAssociatedObject(self, &__AssociatedKeys.notify_key) as? EasyNotification
            {
                return obj
            }
            let obj = EasyNotification()
            self.__notice = obj
            return obj
            
        }
        set {
            objc_setAssociatedObject(self, &__AssociatedKeys.notify_key, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
    }
}




public struct AsMoAtrributeProtocolKeys {
    static var mo = "AsMoAtrributeProtocolKeys.mo"
}

extension  MoAtrributeProtocol where Self:ASDisplayNode
{
    
    
    public func mo_model_willSet(new: NSMutableDictionary) {
        
    }
    
    public func mo_model_reload() {
        
    }
    
    public func mo_model_relase(current: NSMutableDictionary) {
        
    }
    
    
    
    public func mo_detail_willSet(new: NSMutableDictionary) {
        
    }
    
    public func mo_detail_reload() {
        
    }
    
    public func mo_detail_relase(current: NSMutableDictionary) {
        
    }
    public var mo:MoAtrribute{
        get{
            if let obj =  __extention[AsMoAtrributeProtocolKeys.mo] as? MoAtrribute
            {
                return obj
            }
            let newValue = MoAtrribute()
            newValue.ower = self
            
            __extention[AsMoAtrributeProtocolKeys.mo] = newValue
            return newValue
        }
        set{
            self.mo_model_willSet(new: newValue.model)
            self.mo_detail_willSet(new: newValue.detail)
            
            if let obj =  __extention[AsMoAtrributeProtocolKeys.mo] as? MoAtrribute
            {
                self.mo_model_relase(current: obj.model)
                self.mo_detail_relase(current: obj.detail)
            }
            __extention[AsMoAtrributeProtocolKeys.mo] = newValue
            newValue.ower = self
            self.mo_model_reload()
        }
    }
}
extension ASDisplayNode:ControllerSubKitSupport{
    
    private struct Owner_controllerKey {
        static var Owner_controllerKey = "Owner_controllerKey"
    }
    
    @objc public var _mo_owner_controller:UIViewController?{
        get{
            if let obj = objc_getAssociatedObject(self, &Owner_controllerKey.Owner_controllerKey) as? UIViewController
            {
                return obj
            }
            return nil
            
        }
        set{
            objc_setAssociatedObject(self, &Owner_controllerKey.Owner_controllerKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)
        }
        
        
    }
    
    public func getSelfContainerController() -> UIViewController?{
        if let ctr = _mo_owner_controller
        {
            return ctr
        }else{
            if let sv = self.view.superview{
                return sv.getSelfContainerController()
            }
            else{
                return nil
            }
        }
    }
    
}


//
//extension  MoAtrributeProtocol where Self:MoNodeController
//{
//    
//    
//    public func mo_model_willSet(new: NSMutableDictionary) {
//        
//    }
//    
//    public func mo_model_reload() {
//        
//    }
//    
//    public func mo_model_relase(current: NSMutableDictionary) {
//        
//    }
//    
//    
//    
//    public func mo_detail_willSet(new: NSMutableDictionary) {
//        
//    }
//    
//    public func mo_detail_reload() {
//        
//    }
//    
//    public func mo_detail_relase(current: NSMutableDictionary) {
//        
//    }
//    public var mo:MoAtrribute{
//        get{
//            if let obj =  __extention[AsMoAtrributeProtocolKeys.mo] as? MoAtrribute
//            {
//                return obj
//            }
//            let newValue = MoAtrribute()
//            newValue.ower = self
//            
//            __extention[AsMoAtrributeProtocolKeys.mo] = newValue
//            return newValue
//        }
//        set{
//            self.mo_model_willSet(new: newValue.model)
//            self.mo_detail_willSet(new: newValue.detail)
//            
//            if let obj =  __extention[AsMoAtrributeProtocolKeys.mo] as? MoAtrribute
//            {
//                self.mo_model_relase(current: obj.model)
//                self.mo_detail_relase(current: obj.detail)
//            }
//            __extention[AsMoAtrributeProtocolKeys.mo] = newValue
//            newValue.ower = self
//            self.mo_model_reload()
//        }
//    }
//}
//
